from django.core.management.base import BaseCommand, CommandError

from host.models import Host, City, Room
from host.tools.security import AESTool, generate_password


class Command(BaseCommand):
    help = '重置密码'

    def handle(self, *args, **options):
        self.stdout.write('开始重置密码')
        for host in Host.objects.all():
            print(f'{host.ip}重置前密码：{AESTool.decrypt(host.password)}')
            new_password=generate_password(10)
            # 重置主机密码逻辑
            # .....
            host.password=AESTool.encrypt(new_password)
            print(f'{host.ip}重置后密码：{AESTool.decrypt(host.password)}')
            host.save()

        self.stdout.write('重置密码结束')
